#include "ZeroThread.h"

#include <iostream>
#include <pthread.h>

ZeroThread::ZeroThread(FuncPtr_t fptr, void* data)
{
#if defined(ZTHR_PTHREAD)
	int ret;
	ret = pthread_create(&mTid, NULL, fptr, data);
	if (ret) {
		std::cout << "Error: create ZeroThread" << std::endl;
	}
#elif defined(ZTHR_WIN32)
#endif
}

ZeroThread::~ZeroThread()
{
}

bool ZeroThread::cancel()
{
#if defined(ZTHR_PTHREAD)
	int ret = pthread_cancel(mTid);
	if (ret == 0)
		return true;
	std::cout << "Error: cancel Thread: " << ret << std::endl;
	return false;
#elif defined(ZTHR_WIN32)
#endif
}

bool ZeroThread::join()
{
#if defined(ZTHR_PTHREAD)
	int ret = pthread_join(mTid, NULL);
	if (ret == 0)
		return true;
	std::cout << "Error: join Thread: " << ret << std::endl;
	return false;
#elif defined(ZTHR_WIN32)
#endif
}
